﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

namespace WFinger.Web
{
	public partial class _default : WFinger.Web.UI.BasePage
	{
        




		protected string SiteRootPath = WFinger.Common.ServerInfo.GetRootPath();
		protected string dimm = WFinger.Config.UIConfig.dirDumm;
		protected string TempletDir = WFinger.Config.UIConfig.dirTemplet;
		public static string gInstallDir = "{$InstallDir}";
		public static string gTempletDir = "{$TempletDir}";
		protected void Page_Load(object sender, EventArgs e)
		{
			string gChID = Request.QueryString["ChID"];
			int ChID = 0;
			if (gChID != null && gChID != string.Empty)
			{
				if (WFinger.Common.Input.IsInteger(gChID.ToString()))
				{
					ChID = int.Parse(gChID.ToString());
				}
			}
			WFinger.Publish.CommonData.Initialize();
			string indexname = "index.html";
			string TempletPath = WFinger.Common.Public.readparamConfig("IndexTemplet");
			if (ChID != 0)
			{
				TempletPath = "/" + WFinger.Config.UIConfig.dirTemplet + "/" + WFinger.Common.Public.readCHparamConfig("channeltemplet", ChID);
			}
			TempletPath = TempletPath.Replace("/", "\\");
			TempletPath = TempletPath.ToLower().Replace("{@dirtemplet}", TempletDir);
			indexname = WFinger.Common.Public.readparamConfig("IndexFileName");
			WFinger.Publish.Template indexTemp = null;
			if (ChID != 0)
			{
				indexname = WFinger.Common.Public.readCHparamConfig("channelindexname", ChID);
				indexTemp = new WFinger.Publish.Template(SiteRootPath.Trim('\\') + TempletPath, WFinger.Publish.TempType.ChIndex);
			}
			else
			{
				indexTemp = new WFinger.Publish.Template(SiteRootPath.Trim('\\') + TempletPath, WFinger.Publish.TempType.Index);
			}
			indexTemp.GetHTML();
			indexTemp.ReplaceLabels();
			string getContent = indexTemp.FinallyContent;

			if (Regex.Match(getContent, @"\</head\>[\s\S]*\<body", RegexOptions.IgnoreCase | RegexOptions.Compiled).Success)
			{
				getContent = Regex.Replace(getContent, "<body", getjs() + "<body", RegexOptions.IgnoreCase | RegexOptions.Compiled);
			}
			else
			{
				getContent = getjs() + getContent;
			}
			getContent = (getContent.Replace(gInstallDir, WFinger.Common.Public.GetSiteDomain())).Replace(gTempletDir, TempletDir);
			Response.Write(getContent);
		}

		protected string getjs()
		{
            /*
             <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js\"></script>
<script language=\"javascript\" type=\"text/javascript\" src=\"/Templets/js/jquery.easing.js\"></script> 
<script language=\"javascript\" type=\"text/javascript\" src=\"/Templets/js/script.js\"></script>
<script type=\"text/javascript\" src=\"/Templets/js/hoverIntent.js\"></script>
<script type=\"text/javascript\" src=\"/Templets/js/superfish.js\"></script> 
             
             
             */
            //string getajaxJS = "<script language=\"javascript\" type=\"text/javascript\" src=\"" + WFinger.Common.Public.GetSiteDomain() + "/configuration/js/Prototype.js\"></script>\r\n";
            //getajaxJS += "<script language=\"javascript\" type=\"text/javascript\" src=\"" + WFinger.Common.Public.GetSiteDomain() + "/configuration/js/jspublic.js\"></script>\r\n";
            //getajaxJS += "<!--Created by WaveFingerCMS v1.0 For 21ce.cc at " + DateTime.Now + "-->\r\n";
            string getajaxJS = "<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js\"></script>\r\n";
            getajaxJS += "<script language=\"javascript\" type=\"text/javascript\" src=\"/Templets/js/jquery.easing.js\"></script> \r\n";
            getajaxJS += "<script language=\"javascript\" type=\"text/javascript\" src=\"/Templets/js/script.js\"></script>\r\n";
            getajaxJS += "<script type=\"text/javascript\" src=\"/Templets/js/hoverIntent.js\"></script>\r\n";
            getajaxJS += "<script type=\"text/javascript\" src=\"/Templets/js/superfish.js\"></script> \r\n";


            return getajaxJS;
		}

	}
}
